define([
'utils/appFunc',
'components/photo',
'components/geolocation',
'utils/emotion'
],function(appFunc,photo,geo,emotion){
    var Index_addCtrl = {
        init: function(){
         	Index_addCtrl.bindEvent();
			Index_addCtrl.initPost();
        },
		 bindEvent: function(){
            var bindings = [{
                element: '#add_topic',
                event: 'click',
                handler: Index_addCtrl.postMsg
            },{
                element: document,
                selector: '#uploadPicPreview>img',
                event: 'click',
                handler: Index_addCtrl.clearChosenImage
            },{
                element: '#sendWeiboBtn',
                event: 'click',
                handler: Index_addCtrl.postMsg
            },{
                element: 'div.message-tools .get-position',
                event: 'click',
                handler: geo.catchGeoInfo
            },{
                element: '#geoInfo',
                event: 'click',
                handler: geo.cleanGeo
            },{
                element: 'div.message-tools .image-upload',
                event: 'click',
                handler: photo.getPicture
            }];
            appFunc.bindEvents(bindings);
        },
		postMsg:function(){
			var title = $("#messageText" ).html();
			var pid = $("#pid" ).val();
			var pid = $("#pid" ).val();
			var type = $("#type" ).val();
			var store_id=$("#store_id").val();
			var content="";
			if(title==""){
				dialog('内容不能为空啊！！！！');
				return false;
			}
			$.each(photo.uploadInfo, function(i,n) {
			   if (n && !n.isDone) {
				   hiApp.alert('图片上传中，请等待');
					  return false;
				  }
			  });
			  var imgList=$('[data-page="Index_add"] #replyForm').find('input[name="attachid[]"]');
			  $.each(imgList,function(i,v){
				  img=$(v).val();
				  content+='<img index="'+i+'" data="<{ImgDomain}>'+img+'" src="<{ImgDomain}>'+img+'" />';
			  })
			  
			$(this).hide();
			$(".memupostBntHover").show();
			$.post("/BoxApi/BoxSNS/Topic/add",{title:title,content:content,pid:pid,type:type,store_id:store_id},function(data){
				  data=JSON.parse(data);
				  if(data.error>0){
					dialog(data.msg);
				  }else{
					Render_data={0:data.msg};
					var pid=data.msg.pid; 
					var html=box_render(Render_data,"#topicTemplate");
					if($(".group_topic_list_"+pid+" .after_div").length>0){
						$(".group_topic_list_"+pid+" .after_div").prepend(html);
					}
					if($(".group_topic_list_0 .after_div").length>0){
						$(".group_topic_list_0 .after_div").prepend(html);
					}
					if($(".user_topic_list .after_div").length>0){
						$(".user_topic_list .after_div").prepend(html);
					}
					dialog('发送成功',100,function(){
					   history.back();
					});
					
				  }
			 })
		},
		clearSendPopup: function(){
            $('#messageText').val('');
            $('#uploadPicPreview>img').attr('src','');
            $('#uploadPicPreview').hide();
        },
        clearChosenImage: function(){
            hiApp.confirm(i18n.camera.confirm_clear_image,function(){
                $('#uploadPicPreview>img').attr('src','');
                $('#uploadPicPreview').hide();
                localStorage.removeItem('imageUrl');
            });
        },
		initPost:function(){
			photo.initUpload();
			hiApp.hideIndicator();
			 // 表情开关
			emotion.init();
			emotion.hide();
			$(".expreSelect").click(function() {
             	emotion.show();
				$(".tipLayer .photoList").hide();
				$(".photoSelect").removeClass("epOn");
			});
			$(".photoSelect").click(function() {
				 emotion.hide();
				 $(".tipLayer .photoList").show();
				 $(".photoSelect").addClass("epOn");
			});
			
			
		}
		

    };
	Index_addCtrl.bindEvent();
	Index_addCtrl.initPost();
    return Index_addCtrl;
});